package test.enba.mq.producer.controller.rabbitmq.topic;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicExchangeConfig {

  // 定义主题交换器
  @Bean
  public TopicExchange topicExchange() {
    return new TopicExchange("topic-exchange");
  }

  // 定义队列
  @Bean
  public Queue topicQueueA() {
    return new Queue("topic-queue-a");
  }

  @Bean
  public Queue topicQueueB() {
    return new Queue("topic-queue-b");
  }

  // 绑定队列到交换器，并指定路由键模式
  @Bean
  public Binding topicBindingA(TopicExchange topicExchange, Queue topicQueueA) {
    return BindingBuilder.bind(topicQueueA).to(topicExchange).with("topic.*");
  }

  @Bean
  public Binding topicBindingB(TopicExchange topicExchange, Queue topicQueueB) {
    return BindingBuilder.bind(topicQueueB).to(topicExchange).with("topic.#");
  }
}
